<template>
	<view class="user_info_box box">
		<view class="user_info_container">
			<view class="user_info_box_top">
				<view class="user_info_box_top_img">
					<image src="https://img.js.design/assets/img/61249c2c13dce5e53a58bc37.png" mode=""></image>
				</view>
				<view class="user_info_box_top_name">
					{{model1.userInfo.studentName || '暂无'}}
				</view>
				<view class="user_info_box_top_desc">
					学号{{model1.userInfo.studentId || '暂无'}} 宿舍{{model1.userInfo.roomNumber || '(暂无)'}}号
				</view>
				<!-- 				<view class="user_info_box_top_detail">
					姓名、性别、联系电话、身份证号、学校、二级学院、专业、班级、学号、实习周期（天）、紧急联系电话、人员类别（选项：集中实习学生、企业实习生、教师、其它）、入住时间、预计退宿时间，入住状态（已预约、已入住、已退宿）
					学生填写信息后，学生提交后不能在修改，只能由管理修改
				</view> -->
			</view>
			<view class="user_info_box_center">
				<view class="user_info_box_center_title">
					个人基本信息
				</view>
				<view class="user_info_box_center_list">
					<u--form labelPosition="left" :model="model1" :rules="rules" ref="uForm">
						<u-form-item label="姓名" prop="userInfo.studentName" borderBottom ref="item1">
							<u--input v-model="model1.userInfo.studentName" border="none"></u--input>
						</u-form-item>
						<u-form-item label="身份证号" prop="userInfo.idCard" borderBottom ref="item1">
							<u--input v-model="model1.userInfo.idCard" border="none"></u--input>
						</u-form-item>
						<u-form-item label="性别" prop="userInfo.sex" borderBottom @click="showSex = true" ref="item1">
							<u--input v-model="model1.userInfo.sex" disabled disabledColor="#ffffff" placeholder="请选择性别"
								border="none"></u--input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item label="二级学院" prop="userInfo.secondaryCollege" borderBottom ref="item1">
							<u--input v-model="model1.userInfo.secondaryCollege" border="none"></u--input>
						</u-form-item>
						<u-form-item label="班号" prop="userInfo.className" borderBottom ref="item1">
							<u--input v-model="model1.userInfo.className" border="none"></u--input>
						</u-form-item>
						<u-form-item label="学号" prop="userInfo.classNum" borderBottom ref="item1">
							<u--input v-model="model1.userInfo.classNum" border="none"></u--input>
						</u-form-item>
						<u-form-item label="联系电话" prop="userInfo.phone" borderBottom ref="item1">
							<u--input v-model="model1.userInfo.phone" border="none"></u--input>
						</u-form-item>
						<u-form-item label="学校" prop="userInfo.school" borderBottom ref="item1">
							<u--input v-model="model1.userInfo.school" border="none"></u--input>
						</u-form-item>
						<u-form-item label="紧急联系电话" prop="userInfo.emergencyPhone" borderBottom ref="item1">
							<u--input v-model="model1.userInfo.emergencyPhone" border="none"></u--input>
						</u-form-item>
						<u-form-item label="入住时间" prop="userInfo.checkTime" borderBottom ref="item1">
							<u--input v-model="model1.userInfo.checkTime" border="none"></u--input>
						</u-form-item>
						<u-form-item label="预计退宿时间" prop="userInfo.expectedCheckTime" borderBottom ref="item1">
							<u--input v-model="model1.userInfo.expectedCheckTime" border="none"></u--input>
						</u-form-item>
						<u-form-item label="入住状态" prop="userInfo.checkStatus" borderBottom ref="item1">
							<u--input v-model="model1.userInfo.checkStatus" border="none"></u--input>
						</u-form-item>
					</u--form>
				</view>
			</view>
			<u-action-sheet :show="showSex" :actions="actions" title="请选择性别" @close="showSex = false"
				@select="sexSelect">
			</u-action-sheet>
			<view class="user_info_box_bottom">
				<view class="" style="margin-bottom: 20rpx;display:flex;justify-content:space-around;"
					@click="updateSchoolUserMethod">
					<button style="width: 35%;background-color: #259CFF;color: white;"
						@click="inputDialogToggle">密码修改</button>
					<button style="width: 50%;background-color: #259CFF;color: white;">修改个人资料</button>
				</view>
				<view class="" style="display: flex;justify-content: space-around;">

					<button style="width: 35%;background-color: #259CFF;color: white;"
						@click="gotoDepositManagement">押金管理</button>
					<button style="width: 35%;background-color: #259CFF;color: white;"
						@click="gotoRepairReportList">设备报修</button>
				</view>
			</view>
			<uni-popup ref="popup" background-color="#fff">
				<view class="popup_box">
					<view class="popup_title">
						修改密码
					</view>
					<view class="popup_inp">
						<input type="text" placeholder="请输入旧密码" v-model="passwordData.oldPassword" />
					</view>
					<view class="popup_inp">
						<input type="text" placeholder="请输入密码" v-model='passwordData.newOnePassword' />
					</view>
					<view class="popup_inp">
						<input type="text" placeholder="请确认密码" v-model='passwordData.newTwoPassword' />
					</view>
					<view class="popup_btn">
						<button @click="cancelUpdataPassword">取消</button>
						<button @click="UpdataPassword">确定</button>
					</view>
				</view>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	import {
		getWxUserInfo,
		updateSchoolUser,
		changePassword
	} from "../../api/request.js"
	export default {
		data() {
			return {
				passwordData: {
					oldPassword: '',
					newTwoPassword: '',
					newOnePassword: ''
				},
				userInfoData: [],
				showSex: false,
				actions: [{
						name: '男',
						id: 0
					},
					{
						name: '女',
						id: 1
					},
				],
				model1: {
					userInfo: {
						name: '',
						sex: '',
						checkInTime: null,
						checkStatus: null,
						classs: null,
						depositMoney: null,
						dormitoryId: null,
						dormitoryManager: null,
						expectCheckOutTime: null,
						idCard: null,
						internshipCycle: null,
						major: null,
						openId: null,
						password: null,
						personNo: null,
						personType: null,
						phone: null,
						roomNumber: null,
						school: null,
						secondaryCollege: null,
						sex: null,
						signInStatus: null,
						status: null,
						studentId: null,
						studentName: null,
						urgentPhone: null,
						phone: null,
						checkStatus: null,
						expectedCheckTime: null,
						secondaryCollege: null
					},
				},
				rules: {
					'userInfo.name': {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur']
					},
					'userInfo.sex': {
						type: 'string',
						max: 1,
						required: true,
						message: '请选择男或女',
						trigger: ['blur', 'change']
					},
					'userInfo.idCard': {
						type: 'string',
						len: 18,
						required: true,
						message: '请输入身份证号码',
						trigger: ['blur']
					},
					'userInfo.secondaryCollege': {
						type: 'string',
						required: true,
						message: '请输入学院名称',
						trigger: ['blur']
					},
					'userInfo.className': {
						type: 'string',
						required: true,
						message: '请输入班号',
						trigger: ['blur']
					},
					'userInfo.classNum': {
						type: 'string',
						required: true,
						message: '请输入学号',
						trigger: ['blur']
					},
				},
			};
		},
		onLoad() {
			this.getData()
		},
		methods: {
			async UpdataPassword() {
				let res = await changePassword({
					id: this.model1.userInfo.id,
					newOnePassword: this.passwordData.newOnePassword,
					newTwoPassword: this.passwordData.newTwoPassword,
					oldPassword: this.passwordData.oldPassword
				})
				this.$refs.popup.close()
				uni.showToast({
					title: res.data.msg,
					duration: 2000
				})
			},
			cancelUpdataPassword() {
				this.$refs.popup.close()
			},
			dialogInputConfirm() {},
			async updateSchoolUserMethod() {
				let res = await updateSchoolUser(this.model1.userInfo)
				uni.showToast({
					title: res.msg
				})
				console.log(res);
			},
			sexSelect(e) {
				this.model1.userInfo.sex = e.name
				this.$refs.uForm.validateField('userInfo.sex')
				console.log(e);
			},
			inputDialogToggle() {
				this.$refs.popup.open()
			},
			hideKeyboard(e) {
				console.log(e);
			},
			gotoDepositManagement() {
				console.log(this.model1.userInfo, 'this.model1.userInfo');
				uni.navigateTo({
					url: "/pages/depositManagement/depositManagement?userInfo=" + JSON.stringify(this.model1
						.userInfo)
				})
			},
			gotoRepairReportList() {
				uni.navigateTo({
					url: "/pages/repairReportList/repairReportList"
				})
			},
			async getData() {
				let data = await getWxUserInfo()
				console.log(data, 'getWxUserInfo');
				this.model1.userInfo = data.data
			}
		}
	}
</script>

<style lang="scss">
	.user_info_box_bottom {
		button {
			width: 40% !important;
		}
	}

	.popup_box {
		width: 80vw;
		height: 40vh;
		border-radius: 20rpx;
		margin: auto;
		display: flex;
		padding: 20rpx;
		justify-content: space-around;
		flex-direction: column;

		.popup_title {
			width: 100%;
			text-align: center;
			margin: 20rpx 0;
		}

		.popup_inp {
			margin: 20rpx 0;

			input {
				width: 80% !important;
				margin: auto;
			}
		}

		.popup_btn {
			display: flex;
			justify-content: space-around;

			button {
				width: 35%;
			}
		}
	}

	input {
		padding-left: 20rpx;
	}

	.u-form-item__body__left {
		width: 120rpx !important;
	}

	.u-form-item__body__right {
		width: 25%;
		overflow: hidden;
	}

	.user_info_container {
		width: 90%;
		margin: auto;
		display: flex;
		flex-direction: column;

		.user_info_box_top {
			display: flex;
			flex-direction: column;

			.user_info_box_top_img {
				margin: auto;

				image {
					width: 179.64rpx;
					height: 179.64rpx;
					border-radius: 50%;
				}
			}

			.user_info_box_top_name {
				width: 100%;
				font-size: 44.91rpx;
				font-weight: 400;
				letter-spacing: 0rpx;
				line-height: 61.62rpx;
				color: rgba(0, 33, 80, 1);
				text-align: center;
				vertical-align: top;
				margin: auto;
			}

			.user_info_box_top_desc {
				font-size: 26.95rpx;
				font-weight: 400;
				letter-spacing: 1.12rpx;
				line-height: 36.96rpx;
				color: rgba(122, 134, 154, 1);
				text-align: center;
				vertical-align: top;
				width: 100%;
				margin: auto;
			}

			.user_info_box_top_detail {
				font-size: 24rpx;
				font-weight: 400;
				letter-spacing: 0rpx;
				color: rgba(166, 166, 166, 1);
				text-align: left;
				vertical-align: top;
			}
		}

		.user_info_box_center {
			display: flex;
			flex-direction: column;
			margin-top: 20rpx;

			.user_info_box_center_title {
				font-size: 35.75rpx;
				font-weight: 400;
				letter-spacing: -0.43rpx;
				line-height: 49.06rpx;
				color: rgba(51, 51, 51, 1);
				text-align: left;
				vertical-align: top;
			}

			.user_info_box_center_list {}
		}
	}

	input {
		background-color: #EBE8E8 !important;
		width: 586.08rpx !important;
		height: 62.87rpx !important;
		opacity: 1 !important;
		border-radius: 11.23rpx !important;
		padding-left: 20rpx !important;
	}
</style>